/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/13
 * Time: 01:15
 */
public class Solution {
    public int[] twoSum(int[] price, int target) {
        int left = 0;
        int right = price.length - 1;
        int[] result = new int[2];
        while (left < right) {
            if(price[left] + price[right] == target){
                result[0] = price[left];
                result[1] = price[right];
                break;
            }else if(price[left] + price[right] < target){
                left++;
            }else {
                right--;
            }
        }
        return result;
    }
    public static void main(String[] args) {
        Solution s = new Solution();
        int[] ret = s.twoSum(new int[]{2, 7, 11, 15}, 9);
        for (int cur : ret) {
            System.out.print(cur + " ");
        }
    }
}